<%@ page import="java.io.*, java.text.*, java.util.Date, java.sql.*, javax.servlet.*, javax.servlet.http.*, java.util.*" %>
<%
String usernameSC = (String) session.getAttribute("session_name");
String idSC = (String) session.getAttribute("id");
String driver ="com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/projects";
String username = "ia";
String password = "123";
String name;
String col = "";
String data = "";
String fontStyle = "";
String fontSize = "";
String[] events = new String[4];
int index= 0;
SimpleDateFormat time = new SimpleDateFormat("hh:mm:ss a");
SimpleDateFormat day = new SimpleDateFormat("MM/dd/yyyy");
events[2]= day.format(new Date());
events[3]= time.format(new Date());
events[0]="username: (" + usernameSC + ") sign out";
events[1] = "Logout successful";
try
{
	Class.forName(driver).newInstance();
	Connection connection = DriverManager.getConnection(url, username, password);
	Statement statement = connection.createStatement();
	ResultSet rs2 = statement.executeQuery("SELECT COUNT(*) FROM events");
	rs2.next();
	int counter  = rs2.getInt(1);
//--------------------------------------------------------------
//----------- add events----------------------------------------
//--------------------------------------------------------------
	
	if(counter > 0)
	{
		ResultSet rs3=statement.executeQuery("SELECT MAX(no) FROM events");
		rs3.next();
		int max = rs3.getInt(1);
		counter = max+1;
	}
	else
		counter = 1;
	
	String query= "INSERT INTO events values ("+counter + ",'"+events[0]+"','"+events[1]+"','"+events[2]+"','"+events[3]+"','login')";
	statement.executeUpdate(query);
	}catch(ClassNotFoundException cnfe)
	{
		out.println("<br>Couldn't find class file" + cnfe); 
	}catch(SQLException sqle)
	{
		out.println("<br>SQL Exception: " + sqle);
	}catch(InstantiationException ie)
	{
		out.println("<br>Instant exception : " + ie);
	}catch(IllegalAccessException iae)
	{
		out.println("<br>Illegal access exception : " + iae);
	}
session.removeAttribute("session_name");
session.removeAttribute("id");
session.removeAttribute("type");

response.sendRedirect("index.jsp");
%>